import { Injectable } from '@angular/core';
import { HeroService } from './hero.service';

@Injectable({
  providedIn: 'root'
})
export class StorageService {

  public name:string="--";
  public logo:string="assets/images/head.jpg";
  public company:string="公司名称";
  constructor(private heroService: HeroService) { }

  setItem(key,value){
     localStorage.setItem(key,JSON.stringify(value));
  }

  getItem(key){
    return JSON.parse(localStorage.getItem(key));
  }

  removeItem(key){
    localStorage.removeItem(key);
  }

  getUserInfo(){
    // 获取用户信息
    let url=host+"/main/info";
    console.log(this.name);
    return this.heroService.get(url).then(result =>{
        this.name=result.data.name;
        console.log(this.name);
        if(result.data.merchant.logo){
          this.logo=result.data.merchant.logo;
        }
        this.company=result.data.merchant.name;
        this.setItem('type',result.data.type);
      })
  }

}
